<?php
/**
 * @author:hfh
 * @description:根据114.80.208.233上面设计提交的最新模板，对模板进行压缩和导出zip包，然后发布到
**/
class PublishTemplate
{
	private $param1;//案例模板主机名
	private $param2;//目录和Gif图片命名
	private $param3;//产品标识汉字名称
	private $param4; //screenshot流水号
	private $param5; //模板行业类别
	
	
	public function __construct()
	{
		
	}
	
	//---------------主流程[start]------------------
	public function publishProcess($password,$param1,$param2,$param3,$param4,$param5)
	{
		$this->init();
		if($password != '1273jui!@evef')//wsdl密码
		{
			$this->write_log("调用接口密码错误");
			return "调用接口密码错误";
		}
			
		//$this->maxid = $param4;
		$arr_tmp1 = explode("-",$param2);
		$param4 = $arr_tmp1[0].$arr_tmp1[1][0].$arr_tmp1[1][1].$arr_tmp1[2];
		
		$this->param1 = $param1;//案例模板主机名
		$this->param2 = $param2;//目录和Gif图片命名
		$this->param3 = $param3;//产品标识汉字名称
		$this->param4 = $param4;//screenshot流水号
		$this->param5 = $param5;//模板行业类别
		$this->tmp = '';

		$param1 = $this->param1;

		$return_str = '';

		$return_str = $this->check_isPublish();//判断是否符合发布条件
		if($return_str != 'ok') return $return_str;

		$return_str = $this->export_db("{$param1}");//导出数据库到文本
		if($return_str != 'ok') return $return_str;

		$this->optimization();//修改frendlinks和取出sql文件乱码
		$this->file_copy();//copy案例网站upload和template

		//$this->update_file_index();//删除index.php与重命名index.php

		$return_str = $this->file_zip();//压缩upload和sql
		if($return_str != 'ok') return $return_str;

		$this->tmp = $this->update_template();//修改template

		$return_str = $this->file_zip1($this->tmp);//压缩
		if($return_str != 'ok') return $return_str;

		$return_str = $this->insert_db();//写入数据库
		if($return_str != 'ok') return $return_str;

		$return_str = $this->ftp_files();//把生成的临时文件上传到多台服务器上
		if($return_str != 'ok') return $return_str;

		$return_str = $this->end();//删除临时文件
		if($return_str != 'ok') return $return_str;
		return "ok";
	}
	//---------------主流程[end]--------------------
	
	//---------------初始操作处理函数[start]------------------------
	public function init()
	{
		ini_set('display_errors','off');
		error_reporting(0);//屏蔽建议或警告信息
		set_time_limit(0);//php脚本无时间限制

		//从233获取i_order流水号
		$link1 = mysql_connect("localhost","root","eyudda9lB6rVk83u");
		mysql_select_db('tpl_service');
		$result = array();
		$row = array();
		$result = mysql_query("SELECT id FROM ezsite_new_templates ORDER BY id DESC");
		$row = mysql_fetch_array($result,MYSQL_NUM);
		$maxid = $row[0];
		mysql_free_result($result);			
		$maxid = intval($maxid);
		$maxid++;
		mysql_close($link1);

		$this->maxid = $maxid;
		$this->write_log("-------------{$param2}发布开始-------------");
	}
	//---------------初始操作处理函数[end]--------------------------
	
	//---------------判断是否具备待发布条件[start]-------------
	/*
	审核条件:
	1.template下面只有一个目录即当前模板目录
	2.
	*/
	public function check_isPublish()
	{
		$param1 = $this->param1;
		if(!file_exists("D:/wwwroot/{$param1}/wwwroot/template"))
		{
			$this->write_log("D:/wwwroot/{$param1}/wwwroot/template不存在");
			return "D:/wwwroot/{$param1}/wwwroot/template不存在";
		}
		
		$have_gif = false;
		$have_jpg = false;
		
		$files = array();
		$file_folders = array();
		$file_folders = scandir("D:/wwwroot/$param1/wwwroot/template");
		if(count($file_folders) != 3)
		{
			$this->write_log("D:/wwwroot/{$param1}/wwwroot/template下的文件夹数目错误");
			return "D:/wwwroot/{$param1}/wwwroot/template下的文件夹数目错误";
		}
		
		foreach($file_folders as $v)
		{
			if($v == '.' || $v == '..') continue;
			if(!is_dir("D:/wwwroot/$param1/wwwroot/template/{$v}"))
			{
				$this->write_log("D:/wwwroot/$param1/wwwroot/template/{$v}是文件");
				return "D:/wwwroot/$param1/wwwroot/template/{$v}是文件";
			}
			
			$files = scandir("D:/wwwroot/$param1/wwwroot/template/{$v}");
			foreach($files as $v)
			{
				if($v == '.' || $v == '..') continue;
				if(substr($v,-3,3) == 'gif') $have_gif = true;
				if(substr($v,-3,3) == 'jpg') $have_jpg = true;
			}
		}
		
		if(!$have_gif)
		{
			$this->write_log("D:/wwwroot/{$param1}/wwwroot/template下的模板缺少gif图片");
			return "D:/wwwroot/{$param1}/wwwroot/template下的模板缺少gif图片";
		}
		
		if(!$have_jpg)
		{
			$this->write_log("D:/wwwroot/{$param1}/wwwroot/template下的模板缺少jpg图片");
			return "D:/wwwroot/{$param1}/wwwroot/template下的模板缺少jpg图片";
		}
		return 'ok';
	}
	//---------------判断是否具备待发布条件[end]---------------
	
	//-------------导出数据库[start]-----------------
	public function export_db($db_name)
	{
		$param2 = $this->param2;
		$db_host = 'localhost';
		$db_user = 'root';
		$db_password = 'eyudda9lB6rVk83u';
		$db_prefix = 'ezstdb_';
		$database_name = $db_prefix.$db_name;
		
		$file_name = "{$param2}_2_sample.sql";
		if(file_exists($file_name))
		{
			unlink("./$file_name");
		}
		
		$link = mysql_connect($db_host,$db_user,$db_password);
		if(!$link)
		{
			$this->write_log("{$time}:主机名:$db_host 用户名:$db_user 密码:$db_password,连接数据库失败");
			return "{$time}:主机名:$db_host 用户名:$db_user 密码:$db_password,连接数据库失败";
		}
		mysql_select_db($database_name, $link);
		mysql_query("SET NAMES utf8",  $link);
		
		//导出数据表列表
		$tables = array('ss_admin_shortcuts',
						'ss_articles',
						'ss_article_categories',
						'ss_background_musics',
						'ss_backups','ss_bulletins',
						'ss_delivery_addresses',
						'ss_delivery_methods',
						'ss_downloads',
						'ss_download_categories',
						'ss_friendlinks',
						'ss_marquees',
						'ss_menus',
						'ss_menu_items',
						'ss_messages',
						'ss_module_blocks',
						'ss_onlinepay_histories',
						'ss_online_orders',
						'ss_online_qqs',
						'ss_order_products',
						//'ss_payment_accounts',
						//'ss_payment_providers',
						'ss_products',
						'ss_product_categories',
						'ss_product_pics',
						//'ss_roles',
						'ss_site_infos',
						'ss_static_contents',
						'ss_templates',
						'ss_template_categories',
						'ss_transactions'
					);
		
		foreach($tables as $k => $v)
		{
			$sql .= $this->data2sql($v);
		}
		$sql_prefix = <<<SQLPREFIX
-- PHP Code Generate
--
-- Host: localhost    Database: {$database_name}
-- ------------------------------------------------------
-- Server version	5.1.46-community

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
SQLPREFIX;
		
		$sql = $sql_prefix."\r\n".$sql;
		chmod($file_name,0755);
		
		if (!$handle = fopen("./$file_name", 'a'))
		{
			$this->write_log("导出{$file_name}失败");
			return "导出{$file_name}失败";
		}
		if (fwrite($handle, $sql) === FALSE) {
			$this->write_log("$file_name不能写");
			return "$file_name不能写";
		}
		fclose($handle);
		$this->write_log("导出{$database_name}到{$file_name}成功");
		return 'ok';
	}
	
	public function data2sql($table)
	{
		$prefix = <<<SQL
--
-- Dumping data for table `{$table}`
--
SQL;
		$tabledump = $prefix."\r\n\r\n"."LOCK TABLES `{$table}` WRITE;\r\n";
		$tabledump = $tabledump."/*!40000 ALTER TABLE `{$table}` DISABLE KEYS */;\r\n";
		$rows = mysql_query("SELECT * FROM $table");
		$numfields = mysql_num_fields($rows);
		$numrows = mysql_num_rows($rows);
		$i = 1;
		while ($row = mysql_fetch_row($rows))
		{
			$comma = "";
			if($i == 1)
			{
				$tabledump .= "INSERT INTO `{$table}` VALUES(";
			}
			else
			{
				$tabledump .= "(";
			}

			for($i = 0; $i < $numfields; $i++)
			{
				$tabledump .= $comma."'".mysql_escape_string($row[$i])."'";
				$comma = ",";
			}
			$tabledump .= "),";
			$i++;
		}
		$tabledump = substr($tabledump,0,strlen($tabledump)-1);
		$tabledump .= ";\r\n/*!40000 ALTER TABLE `{$table}` ENABLE KEYS */;\r\nUNLOCK TABLES;\r\n\r\n";
		return $tabledump;
	}
	//-------------导出数据库[end]-------------------
	
	//-------------解决friendlinks问题和sql文件乱码[start]----------
	public function optimization()
	{
		$param2 = $this->param2;
		//增加friendlinks导入字段
		$filename = $param2 . '_2_sample.sql';
		$str1 = file_get_contents ("./{$filename}");
		$str2 = str_replace ('INSERT INTO `ss_friendlinks`','INSERT INTO `ss_friendlinks`(`id`,`fl_name`,`fl_img`,`fl_addr`,`s_locale`,`create_time`,`for_roles`,`published`)',$str1);
	
		//去除friendlinks 1，1问题
		$matches = array();
		preg_match("/INSERT INTO `ss_friendlinks`.*/i",$str2,$matches);
		$replace_content = str_replace("'1','1'","'1'",$matches[0]);
		$str2 = preg_replace("/INSERT INTO `ss_friendlinks`.*/i",$replace_content,$str2);

		//去除模板sql乱码
		$i = 0;
		for($i = 0;$i < 5;$i++)//乱码出现在前5个字符
		{
			if($str2[$i] == '-' || $str2[$i] == '/')
			{
				break;
			}
		}
		
		$i--;//获取乱码位置
		while($i >= 0)
		{
			$str2[$i] = '-';
			$i--;
		}
	
		file_put_contents ("./$filename",$str2);
		$this->write_log("{$filename}修改frendlinks和去除乱码成功");
	}
	//-------------解决friendlinks问题和sql文件乱码[end]----------
	
	//-------------copy[start]----------
	public function file_copy()
	{
		$param1 = $this->param1;
		$param2 = $this->param2;

		$this->xCopy("D:/wwwroot/{$param1}/wwwroot/upload","./{$param2}_2_upload",1);
		$this->write_log("D:/wwwroot/{$param1}/wwwroot/upload拷贝成功");
		$this->xCopy("D:/wwwroot/{$param1}/wwwroot/template","./template",1);
		$this->write_log("D:/wwwroot/{$param1}/wwwroot/template拷贝成功");
	}
	
	public function xCopy($source, $destination, $child)
	{
		$boolean = false;
		if(!is_dir($source))
		{
			$this->write_log("拷贝upload或template失败，源目录错误");
			return "拷贝upload或template失败，源目录错误";
		}
		if(!is_dir($destination))
		{
			mkdir($destination,0755);
		}
	
		$handle = dir($source);
		while($entry = $handle->read())
		{
			if(($entry != ".")&&($entry != ".."))
			{
				if(is_dir($source."/".$entry))
				{
					if($child)
					$this->xCopy($source."/".$entry,$destination."/".$entry,$child);
				}
				else
				{
					$boolean = copy($source."/".$entry,$destination."/".$entry);
					if(!$boolean)
					{
						$this->write_log("拷贝upload或template失败");
						return "拷贝upload或template失败";
					}
				}
			}
		}
		return true;
	}
	//-------------copy[end]----------
	
	//---------------删除index.php与重命名index.php[start]--------------
	public function update_file_index()
	{
		$param1 = $this->param1;
		$boolean = false;
		if(file_exists("D:/wwwroot/{$param1}/wwwroot/index.php"))
		{
			chmod("D:/wwwroot/{$param1}/wwwroot/index.php",0755);
			unlink("D:/wwwroot/{$param1}/wwwroot/index.php");
			$boolean = rename("D:/wwwroot/{$param1}/wwwroot/index_.php","D:/wwwroot/{$param1}/wwwroot/index.php");
			if(!$boolean)
			{
				$this->write_log("重命名D:/wwwroot/{$param1}/wwwroot/index.php失败");
			}
			$this->write_log("删除和重命名D:/wwwroot/{$param1}/wwwroot/index.php成功");
		}
	}
	//---------------删除index.php与重命名index.php[end]--------------
	
	//---------------压缩upload和sql[start]--------------------
	public function file_zip()
	{
		$param2 = $this->param2;
		if(!file_exists('./dsm'))
		{
			mkdir('./dsm',0755);
		}
		
		if(!file_exists('./zjc'))
		{
			mkdir('./zjc',0755);
		}
		
		//压缩upload
		$zip = new Zipper;
		$res = $zip->open("./dsm/{$param2}.zip", ZipArchive::CREATE);
		if ($res === true)
		{
			$zip->addDir("{$param2}_2_upload");
			$zip->close();
		} 
		else 
		{
			$this->write_log("压缩{$param2}_2_upload失败");
			return "压缩{$param2}_2_upload失败";
		}
		
		//把sql文件加入压缩包
		$zip1 = new ZipArchive;
		if ($zip1->open("./dsm/{$param2}.zip") === true)
		{
		    $zip1->addFile("{$param2}_2_sample.sql");
		    $zip1->close();
		}
		else
		{
		    $this->write_log("压缩{$param2}_2_sample.sql失败");
			return "压缩{$param2}_2_sample.sql失败";
		}
		
		$zip2 = new Zipper;
		$res = $zip2->open("./zjc/{$param2}_2_upload.zip", ZipArchive::CREATE);
		
		if ($res === true)
		{
			$this->xCopy("{$param2}_2_upload/image","./image",1);
			$this->xCopy("{$param2}_2_upload/flash","./flash",1);
			$this->xCopy("{$param2}_2_upload/media","./media",1);
			$this->xCopy("{$param2}_2_upload/file","./file",1);
			
			$zip2->addDir("image");
			$zip2->addDir("flash");
			$zip2->addDir("media");
			$zip2->addDir("file");
			$zip2->close();
			$bool = $this->full_rmdir('./image');
			$bool = $this->full_rmdir('./flash');
			$bool = $this->full_rmdir('./media');
			$bool = $this->full_rmdir('./file');
		} 
		else 
		{
			$this->write_log("压缩{$param2}_2_upload.zip失败");
			return "压缩{$param2}_2_upload.zip失败";
		}
		$this->write_log("压缩sql和upload成功");
		return 'ok';
	}
	
	public function file_zip1($path)
	{
		$param2 = $this->param2;
		
		$zip = new Zipper;
		$res = $zip->open("./{$param2}.zip", ZipArchive::CREATE);
		if ($res === true)
		{
			rename("images","tmp_images");
			$this->xCopy("{$path}/css","./css",1);
			$this->xCopy("{$path}/images","./images",1);
			$this->xCopy("{$path}/layout","./layout",1);
			$zip->addDir("css");
			$zip->addDir("images");
			$zip->addDir("layout");
			$zip->close();
			$bool = $this->full_rmdir('./css');
			$bool = $this->full_rmdir('./images');
			$bool = $this->full_rmdir('./layout');
			rename("tmp_images","images");
		} 
		else 
		{
			$this->write_log("压缩{$param2}.zip失败");
			return "压缩{$param2}.zip失败";
		}
		
		$zip1 = new ZipArchive;
		if ($zip1->open("./{$param2}.zip") === TRUE)
		{
			copy($path."conf.php",'./conf.php');
			copy($path."template_info.php",'./template_info.php');
			copy($path."screenshot.jpg",'./screenshot.jpg');
		    $zip1->addFile("conf.php");
		    $zip1->addFile("template_info.php");
		    $zip1->addFile("screenshot.jpg");
		    $zip1->close();
			unlink('./conf.php');
			unlink('./template_info.php');
			unlink('./screenshot.jpg');
		}
		else
		{
		   	$this->write_log("压缩{$param2}.zip失败");
			return "压缩{$param2}.zip失败";
		}
		
		$this->write_log("压缩{$param2}.zip成功");
		return 'ok';
	}
	//---------------压缩upload和sql[end]--------------------
	
	//---------------修改template[start]-----------------
	public function update_template()
	{
		$param2 = $this->param2;
		$param4 = $this->param4;
		$tmp = '';
		$arr = array();
		$arr1 = array();

		$arr = scandir('./template');
		foreach($arr as $v)
		{
			if($v == '.' || $v == '..')	continue;
			
			$tmp = "./template/{$v}/";
			$arr1 = scandir("./template/{$v}");
			foreach($arr1 as $v1)
			{
				if(substr($v1,-3,3) == 'gif')
				{
					rename("./template/{$v}/{$v1}","./template/{$v}/{$param2}.gif");
				}
				
				if($v1 == 'conf.php')
				{
					unlink("./template/{$v}/conf.php");
					if(!file_exists('./conf.php'))
					{
						file_put_contents('./conf.php', '');
					}
					copy("./conf.php","./template/{$v}/conf.php");
					$this->createConf("./template/{$v}/");
				}
				
				if($v1 == 'template_info.php')
				{
					rename("./template/{$v}/template_info.php", "./template/{$v}/bak.php");
					$this->template_info("./template/{$v}/");
					rename("./template/{$v}/tmp.php", "./template/{$v}/template_info.php");
				}
			}
		}
		
		if(file_exists($tmp.'screenshot.jpg'))
		{
			copy($tmp.'screenshot.jpg',"./$param4.jpg");
		}
		
		if(file_exists($tmp."{$param2}.gif"))
		{
			copy($tmp."{$param2}.gif","./{$param2}.gif");
		}

		$this->write_log("修改template成功");
		return $tmp;
	}
	//---------------修改template[end]-----------------

	//---------------修改tempalate下的conf.php[start]----------------
	public function createConf($path)
	{
		$param2 = $this->param2;
		$param3 = $this->param3;
		
		$str1 = $param2;
		$str2 = $param3;
		
		//$str2_2 = iconv('gbk','UTF-8',$str2);
		$str2_2 = $str2;
		$fp = fopen ($path."conf.php","w");
		
		$line[0] = "<?php" . "\r\n";
		$line[1] = "if (!defined('IN_CONTEXT')) die('access violation error!');" . "\r\n" ;
		$line[2] = '$tpl_name = ' . '"' .$str1 . '"' . ";" . "\r\n" ;
		$line[3] = '$template_name = ' . '"' . $str2_2 .  '"' . ";" . "\r\n" ;
		$line[4] = '?>' ;
		
		foreach ($line as $key => $value) 
		{
			fputs ($fp,$value);
		}
		fclose ($fp);
		$this->write_log("修改tempalate下的conf.php成功");
	}
	//---------------修改tempalate下的conf.php[end]----------------
	
	//---------------修改template下的template_info.php[start]-----------
	public function template_info($path)
	{
		$param2 = $this->param2;
		
		$var = $param2; 
		$fps = fopen($path."bak.php","r");
		if(!$fps)
		{
			$this->write_log("打开{$path}bak.php错误");
			die;
		}
		$fpd = fopen($path."tmp.php","w");
		$i = 0;
		while(!feof($fps))
		{
			$line = fgets($fps);
			$i++;
			if($i != 3)
			{
				fputs($fpd,$line);
				//echo $line;
			}
			else
			{
				fputs($fpd,'public static '. '$name = '."'".$var."'".';'."\r\n");
				//echo 'public static'.' $name = '.'"'.$var.'"'.';'."\n";
			}
		}
		fclose($fpd);
		fclose($fps);
	}
	//---------------修改template下的template_info.php[end]-----------

	//---------------插入数据库[start]-----------
	public function insert_db()
	{
		$param1 = $this->param1;
		$param2 = $this->param2;
		$param3 = $this->param3;
		$param4 = $this->param4;
		$param5 = $this->param5;
		
		$a = $param4;
		$b = $param3;
		$c = $param2;
		$d = $param1;
		$e = $param5;
		$i_order1 = $this->maxid;
		
		$AllFile = <<<START
\$servername = "114.80.208.233"; 
\$username = "tplsvc"; 
\$password = "cvslpt"; 
\$dbname = "tpl_service"; 
\$conn = mysql_connect( \$servername, \$username, \$password); 
mysql_query('set names utf8'); 
mysql_select_db(\$dbname,\$conn); 
\$i_order = $i_order1; 
\$name="企业网站-{$b}"; 
\$archive="{$c}.zip"; 
\$demourl="http://{$d}.site0.sitestar.cn"; 
\$description=""; 
\$screenshot="{$a}.jpg"; 
\$isfree=1; 
\$submitter="_internal"; 
\$n_purchase="0"; 
\$create_time=0; 
\$ezsite_template_category_id = $e; 
\$featured=1; 
\$i_level=2; 
\$is_free=0; 
\$download="http://www.sitestar.cn/bbs/forum-21-1.html"; 
\$tpl_count=0; 
\$sql = "select count(*) as num from ezsite_new_templates where screenshot='\$screenshot'";
\$query = mysql_query(\$sql); 
\$arr = mysql_fetch_array(\$query); 
\$num = \$arr['num']; 
if(\$num > 0){ 
     
}else{
	\$sql = "insert into ezsite_new_templates(`name`,archive,i_order,demourl,description,screenshot,isfree,submitter,n_purchase,create_time,ezsite_template_category_id,featured,i_level,is_free,download,tpl_count) values('\$name','\$archive','\$i_order','\$demourl','\$description','\$screenshot','\$isfree','\$submitter','\$n_purchase','\$create_time','\$ezsite_template_category_id','\$featured','\$i_level','\$is_free','\$download','\$tpl_count')";
	\$query = mysql_query(\$sql); 
	if(\$query){ 
		\$sql = "select * from ezsite_new_templates where featured='1' order by id asc"; 
		\$query = mysql_query(\$sql); 
		\$arr = mysql_fetch_array(\$query); 
		\$_id = \$arr['id']; 
		mysql_query("update ezsite_new_templates set featured='0' where id='\$_id'"); 
	} 
} 
START;
//	file_put_contents("./db.php",$AllFile);
	
	$AllFile1 = <<<START
\$servername = "119.164.255.9"; 
\$username = "tplsvc"; 
\$password = "cvslpt"; 
\$dbname = "tpl_service"; 
\$conn = mysql_connect( \$servername, \$username, \$password); 
mysql_query('set names utf8'); 
mysql_select_db(\$dbname,\$conn); 
\$i_order = $i_order1; 
\$name="企业网站-{$b}"; 
\$archive="{$c}.zip"; 
\$demourl="http://{$d}.site0.sitestar.cn"; 
\$description=""; 
\$screenshot="{$a}.jpg"; 
\$isfree=1; 
\$submitter="_internal"; 
\$n_purchase="0"; 
\$create_time=0; 
\$ezsite_template_category_id = $e; 
\$featured=1; 
\$i_level=2; 
\$is_free=0; 
\$download="http://www.sitestar.cn/bbs/forum-21-1.html"; 
\$tpl_count=0; 
\$sql = "select count(*) as num from ezsite_new_templates where archive='\$archive'"; 
\$query = mysql_query(\$sql); 
\$arr = mysql_fetch_array(\$query); 
\$num = \$arr['num']; 
if(\$num > 0){ 
     
}else{ 
	\$sql = "insert into ezsite_new_templates(`name`,archive,i_order,demourl,description,screenshot,isfree,submitter,n_purchase,create_time,ezsite_template_category_id,featured,i_level,is_free,download,tpl_count) values('\$name','\$archive','\$i_order','\$demourl','\$description','\$screenshot','\$isfree','\$submitter','\$n_purchase','\$create_time','\$ezsite_template_category_id','\$featured','\$i_level','\$is_free','\$download','\$tpl_count')";
	\$query = mysql_query(\$sql); 
	if(\$query){ 
		\$sql = "select * from ezsite_new_templates where featured='1' order by id asc"; 
		\$query = mysql_query(\$sql); 
		\$arr = mysql_fetch_array(\$query); 
		\$_id = \$arr['id']; 
		mysql_query("update ezsite_new_templates set featured='0' where id='\$_id'"); 
	} 
} 
START;
//	file_put_contents("./db1.php",$AllFile1);
	
	$AllFile2 = <<<START
\$servername = "222.218.45.23"; 
\$username = "tplsvc"; 
\$password = "cvslpt"; 
\$dbname = "tpl_service"; 
\$conn = mysql_connect( \$servername, \$username, \$password); 
mysql_query('set names utf8'); 
mysql_select_db(\$dbname,\$conn); 
\$i_order = $i_order1; 
\$name="企业网站-{$b}"; 
\$archive="{$c}.zip"; 
\$demourl="http://{$d}.site0.sitestar.cn"; 
\$description=""; 
\$screenshot="{$a}.jpg"; 
\$isfree=1; 
\$submitter="_internal"; 
\$n_purchase="0"; 
\$create_time=0; 
\$ezsite_template_category_id = $e; 
\$featured=1; 
\$i_level=2; 
\$is_free=0; 
\$download="http://www.sitestar.cn/bbs/forum-21-1.html"; 
\$tpl_count=0; 
\$sql = "select count(*) as num from ezsite_new_templates where archive='\$archive'"; 
\$query = mysql_query(\$sql); 
\$arr = mysql_fetch_array(\$query); 
\$num = \$arr['num']; 
if(\$num > 0){ 
      
}else{ 
	\$sql = "insert into ezsite_new_templates(`name`,archive,i_order,demourl,description,screenshot,isfree,submitter,n_purchase,create_time,ezsite_template_category_id,featured,i_level,is_free,download,tpl_count) values('\$name','\$archive','\$i_order','\$demourl','\$description','\$screenshot','\$isfree','\$submitter','\$n_purchase','\$create_time','\$ezsite_template_category_id','\$featured','\$i_level','\$is_free','\$download','\$tpl_count')";
	\$query = mysql_query(\$sql); 
	if(\$query){ 
		\$sql = "select * from ezsite_new_templates where featured='1' order by id asc"; 
		\$query = mysql_query(\$sql); 
		\$arr = mysql_fetch_array(\$query); 
		\$_id = \$arr['id']; 
		mysql_query("update ezsite_new_templates set featured='0' where id='\$_id'"); 
	} 
} 
START;
//	file_put_contents("./db2.php",$AllFile2);
	
	//php.exe changeuser.php %var1%
	/*
		$dbusermodule = $d;
		$dbhost = "localhost";
		$dbuser = "root";
		$dbpasswd = "eyudda9lB6rVk83u";
		
		$link = mysql_connect($dbhost, $dbuser, $dbpasswd);
		if ($link) 
		{
			mysql_select_db("mysql", $link);
			$result = mysql_query("update mysql.user set `Host`='localhost' where `user`='{$dbusermodule}'");
			if(!$result) 
			{
				$this->write_log("修改233的mysql表失败");
				return "修改233的mysql表失败";
			} 
		} 
		else 
		{
			$this->write_log("连接233数据库失败");
			return "连接233数据库失败";
		}
		mysql_close($link);	
		unset($link);
	
		//changeadminpasswd.php %var1%
		$dbuser = $d;
		$host = 'localhost';
		$passwd = 'SiteStar2010MC()';
	
		$sha = sha1('8KKD&Ujeue__IYW#YghNWEGW_o0Og9ETY22bwgMSJE:LDKLuie3j(&*M^%TG#JH');
		$link = mysql_connect($host,$dbuser,$passwd);
		if ($link) 
		{
			$result = mysql_query("update ezstdb_$dbuser.ss_users set passwd = '{$sha}' where login = 'admin'");
			if (!$result) 
			{
				$this->write_log("修改233的ezstdb_$dbuser数据库的ss_users数据表密码出错");
				return "修改233的ezstdb_$dbuser数据库的ss_users数据表密码出错";
			} 
		} 
		else 
		{
			$this->write_log("连接233数据库失败");
			return "连接233数据库失败"; 
		}
		*/		
		eval($AllFile);
		eval($AllFile1);
		eval($AllFile2);
		$this->write_log("数据库操作成功");
		return 'ok';
	}
	//---------------插入数据库[end]-----------

	//---------ftp传输模板数据[start]-------------
	public function ftp_files()
	{
		$param2 = $this->param2;
		$param4 = $this->param4;
		
		//需要跨站点操作权限
		//--------------本地114.80.08.233(模板服务器)传输数据[start]--------------
		if(!file_exists("./{$param2}_2_sample.sql"))
		{
			$this->write_log("{$param2}_2_sample.sql不存在");
			return "{$param2}_2_sample.sql不存在";
		}
		copy("./{$param2}_2_sample.sql","D:/sitestar2.0_build110425_share_file/installation_sample/sample_data/{$param2}_2_sample.sql");
			
		if(!file_exists("./zjc/{$param2}_2_upload.zip"))
		{
			$this->write_log("zjc/{$param2}_2_upload.zip不存在");
			return "zjc/{$param2}_2_upload.zip不存在";
		}
		copy("./zjc/{$param2}_2_upload.zip","D:/sitestar2.0_build110425_share_file/installation_sample/sample_data/{$param2}_2_upload.zip");
		
		if(!file_exists("./{$param2}.zip"))
		{
			$this->write_log("{$param2}.zip不存在");
			return "{$param2}.zip不存在";
		}
		copy("./{$param2}.zip","D:/sitestar_install_file/tpl_service/templates/template_jingjian/{$param2}.zip");
		
		if(!file_exists("./$param4.jpg"))
		{
			$this->write_log("$param4.jpg不存在");
			return "$param4.jpg不存在";
		}
		copy("./$param4.jpg","D:/sitestar_install_file/tpl_service/htdocs/screenshots/$param4.jpg");
		
		if(!file_exists("./dsm/{$param2}.zip"))
		{
			$this->write_log("dsm/{$param2}.zip不存在");
			return "dsm/{$param2}.zip不存在";
		}
		copy("./dsm/{$param2}.zip","D:/sitestar_install_file/tpl_service/templates/sitestar21_data/{$param2}.zip");
		$this->write_log("114.80.208.233数据发送成功");
		//--------------本地114.80.208.233(模板服务器)传输数据[end]----------------
		
		//--------------119.164.255.9(模板服务器)传输数据[start]--------------		
		/*网络不稳定，手动传输
		$conn_id = ftp_connect('119.164.255.9');
		$login_result = ftp_login($conn_id, 'zhangjichao_sitestar', '2010keuie739oi37ledf763jka732i');
		if ((!$conn_id) || (!$login_result)) 
		{
			$this->write_log("119.164.255.9的ftp连接失败");
			return "119.164.255.9的ftp连接失败";
		} 
		$upload = ftp_put($conn_id, "./templates/template_jingjian/{$param2}.zip", "./{$param2}.zip", FTP_BINARY);
		if (!$upload) 
		{
			$this->write_log("{$param2}.zip传送到119.164.255.9失败");
			return "{$param2}.zip传送到119.164.255.9失败";
		} 
		
		$upload = ftp_put($conn_id, "./templates/sitestar21_data/{$param2}.zip", "./dsm/{$param2}.zip", FTP_BINARY);
		if (!$upload) 
		{
			$this->write_log("{$param2}.zip传送到119.164.255.9失败");
			return "{$param2}.zip传送到119.164.255.9失败";
		}
		
		$upload = ftp_put($conn_id, "./htdocs/screenshots/$param4.jpg", "./$param4.jpg", FTP_BINARY);
		if(!$upload)
		{
			$this->write_log("$param4.jpg传送到119.164.255.9失败");
			return "$param4.jpg传送到119.164.255.9失败";
		}
		ftp_close($conn_id);
		unset($conn_id);	
		$this->write_log("119.164.255.9数据发送成功");	
		*/
		//--------------119.164.255.9传输数据[end]--------------
		
		//--------------222.218.45.23(模板服务器)传输数据[start]--------------
		$conn_id = ftp_connect('222.218.45.23');
		$login_result = ftp_login($conn_id, 'zhangjichao_sitestar', '2010keuie739oi37ledf763jka732i');
		if ((!$conn_id) || (!$login_result)) 
		{
			$this->write_log("222.218.45.23的ftp连接失败");
			return "222.218.45.23的ftp连接失败";
		}
		$upload = ftp_put($conn_id, "./templates/template_jingjian/{$param2}.zip", "./{$param2}.zip", FTP_BINARY);
		if(!$upload)
		{
			$this->write_log("{$param2}.zip传送到222.218.45.23失败");
			return "{$param2}.zip传送到222.218.45.23失败";
		}
		$upload = ftp_put($conn_id, "./templates/sitestar21_data/{$param2}.zip", "./dsm/{$param2}.zip", FTP_BINARY);
		if(!$upload)
		{
			$this->write_log("dsm/{$param2}.zip传送到222.218.45.23失败");
			return "dsm/{$param2}.zip传送到222.218.45.23失败";
		}
		$upload = ftp_put($conn_id, "./htdocs/screenshots/$param4.jpg", "./$param4.jpg", FTP_BINARY);
		if(!$upload)
		{
			$this->write_log("$param4.jpg传送到222.218.45.23失败");
			return "$param4.jpg传送到222.218.45.23失败";
		}
		ftp_close($conn_id);
		unset($conn_id);
		$this->write_log("222.218.45.23数据发送成功");
		//--------------222.218.45.23传输数据[end]--------------
		
		//--------------114.80.208.189传输数据[start]--------------
		/*加快发送速度，暂时不发送
		$conn_id = ftp_connect('114.80.208.189');
		$login_result = ftp_login($conn_id, 'zhangjichao_sitestar', '383jkUElA73815E4');
		if ((!$conn_id) || (!$login_result)) 
		{
			$this->write_log("114.80.208.189的ftp连接失败");
			return "114.80.208.189的ftp连接失败";
		}
		$upload = ftp_put($conn_id, "./{$param2}_2_sample.sql", "./{$param2}_2_sample.sql", FTP_BINARY);
		if(!$upload)
		{
			$this->write_log("{$param2}_2_sample.sql传送到114.80.208.189失败");
			return "{$param2}_2_sample.sql传送到114.80.208.189失败";
		}
		$upload = ftp_put($conn_id, "./{$param2}_2_upload.zip", "./zjc/{$param2}_2_upload.zip", FTP_BINARY);
		if(!$upload)
		{
			$this->write_log("{$param2}_2_upload.zip传送到114.80.208.189失败");
			return "{$param2}_2_upload.zip传送到114.80.208.189失败";
		}
		ftp_close($conn_id);
		unset($conn_id);
		$this->write_log("114.80.208.189数据发送成功");
		*/
		//--------------114.80.208.189传输数据[end]--------------
		
		//--------------114.80.208.83传输数据[start]--------------
		/*加快发送速度，暂时不发送
		$conn_id = ftp_connect('114.80.208.83');
		$login_result = ftp_login($conn_id, 'dongshanmu_sitestar', '383jkUElA73815E4');
		if ((!$conn_id) || (!$login_result)) 
		{
			$this->write_log("114.80.208.83的ftp连接失败");
			return "114.80.208.83的ftp连接失败";
		}
		$upload = ftp_put($conn_id, "./{$param2}_2_sample.sql", "./{$param2}_2_sample.sql", FTP_BINARY);
		if(!$upload)
		{
			$this->write_log("{$param2}_2_sample.sql传送到114.80.208.83失败");
			return "{$param2}_2_sample.sql传送到114.80.208.83失败";
		}
		$upload = ftp_put($conn_id, "./{$param2}_2_upload.zip", "./zjc/{$param2}_2_upload.zip", FTP_BINARY);
		if(!$upload)
		{
			$this->write_log("{$param2}_2_upload.zip传送到114.80.208.83失败");
			return "{$param2}_2_upload.zip传送到114.80.208.83失败";
		}
		ftp_close($conn_id);
		unset($conn_id);
		$this->write_log("114.80.208.83数据发送成功");
		*/
		//--------------114.80.208.83传输数据[end]--------------
		
		//--------------114.80.154.76(建站主站)传输数据[start]--------------
		$conn_id = ftp_connect('114.80.154.76');
		$login_result = ftp_login($conn_id, 'zhangjichao_sitestar', 'zjcsitestar');
		if ((!$conn_id) || (!$login_result)) 
		{
			$this->write_log("114.80.154.76的ftp连接失败");
			return "114.80.154.76的ftp连接失败";
		}
		$upload = ftp_put($conn_id, "./{$param2}.gif", "./{$param2}.gif", FTP_BINARY);
		if(!$upload)
		{
			$this->write_log("{$param2}.gif传送到114.80.154.76失败");
			return "{$param2}.gif传送到114.80.154.76失败";
		}
		ftp_close($conn_id);
		unset($conn_id);
		$this->write_log("114.80.154.76数据发送成功");
		//--------------114.80.154.76传输数据[end]----------------
		
		//--------------58.64.190.8传输数据[start]----------------
		/*加快发送速度，暂时不发送
		$conn_id = ftp_connect('58.64.190.8');
		$login_result = ftp_login($conn_id, 'zhangjichao_sitestar', '383jkUElA76FEE29EB6');
		if ((!$conn_id) || (!$login_result)) 
		{
			$conn_id = ftp_connect('58.64.190.8');
			$login_result = ftp_login($conn_id, 'zhangjichao_sitestar', '383jkUElA76FEE29EB6');//两次试图链接
			if ((!$conn_id) || (!$login_result))
			{
				$this->write_log("58.64.190.8的ftp连接失败");
				return "58.64.190.8的ftp连接失败";
			}
		}
		$upload = ftp_put($conn_id, "./{$param2}_2_sample.sql", "./{$param2}_2_sample.sql", FTP_BINARY);
		if(!$upload)
		{
			$this->write_log("{$param2}_2_sample.sql传送到58.64.190.8失败");
			return "{$param2}_2_sample.sql传送到58.64.190.8失败";
		}
		$upload = ftp_put($conn_id, "./{$param2}_2_upload.zip", "./zjc/{$param2}_2_upload.zip", FTP_BINARY);
		if(!$upload)
		{
			$this->write_log("{$param2}_2_upload.zip传送到58.64.190.8失败");
			return "{$param2}_2_upload.zip传送到58.64.190.8失败";
		}
		ftp_close($conn_id);
		unset($conn_id);
		$this->write_log("58.64.190.8数据发送成功");
		*/
		//--------------58.64.190.8传输数据[end]----------------
		
		//--------------58.64.149.197传输数据[start]----------------
		/*免费建站服务器停止发送数据更新
		$conn_id = ftp_connect('58.64.149.197');
		$login_result = ftp_login($conn_id, 'zhangjichao_sitestar', 'zjcsitestar');
		if ((!$conn_id) || (!$login_result)) 
		{
			$conn_id = ftp_connect('58.64.149.197');
			$login_result = ftp_login($conn_id, 'zhangjichao_sitestar', 'zjcsitestar');//两次试图链接
			if ((!$conn_id) || (!$login_result))
			{
				$this->write_log("58.64.149.197的ftp连接失败");
				return "58.64.149.197的ftp连接失败";
			}
		}
		$upload = ftp_put($conn_id, "./{$param2}_2_sample.sql", "./{$param2}_2_sample.sql", FTP_BINARY);
		if(!$upload)
		{
			$this->write_log("{$param2}_2_sample.sql传送到58.64.149.197失败");
			return "{$param2}_2_sample.sql传送到58.64.149.197失败";
		}
		$upload = ftp_put($conn_id, "./{$param2}_2_upload.zip", "./zjc/{$param2}_2_upload.zip", FTP_BINARY);
		if(!$upload)
		{
			$this->write_log("{$param2}_2_upload.zip传送到58.64.149.197失败");
			return "{$param2}_2_upload.zip传送到58.64.149.197失败";
		}
		ftp_close($conn_id);
		unset($conn_id);
		$this->write_log("58.64.149.197数据发送成功");
		*/
		//--------------58.64.149.197传输数据[end]----------------
		
		//--------------58.64.186.114传输数据[start]----------------
		/*免费建站服务器停止发送数据
		$conn_id = ftp_connect('58.64.186.114');
		$login_result = ftp_login($conn_id, 'zhangjichao_sitestar', '2010keuie739oi37ledf763jka732i');
		if ((!$conn_id) || (!$login_result)) 
		{
			$conn_id = ftp_connect('58.64.186.114');
			$login_result = ftp_login($conn_id, 'zhangjichao_sitestar', '2010keuie739oi37ledf763jka732i');//两次试图链接
			if ((!$conn_id) || (!$login_result))
			{
				$this->write_log("58.64.186.114的ftp连接失败");
				return "58.64.186.114的ftp连接失败";
			}
		}
		$upload = ftp_put($conn_id, "./{$param2}_2_sample.sql", "./{$param2}_2_sample.sql", FTP_BINARY);
		if(!$upload)
		{
			$this->write_log("{$param2}_2_sample.sql传送到58.64.186.114失败");
			return "{$param2}_2_sample.sql传送到58.64.186.114失败";
		}
		$upload = ftp_put($conn_id, "./{$param2}_2_upload.zip", "./zjc/{$param2}_2_upload.zip", FTP_BINARY);
		if(!$upload)
		{
			$this->write_log("{$param2}_2_upload.zip传送到58.64.186.114失败");
			return "{$param2}_2_upload.zip传送到58.64.186.114失败";
		}
		ftp_close($conn_id);
		unset($conn_id);
		$this->write_log("58.64.186.114数据发送成功");
		*/
		//--------------58.64.186.114传输数据[end]----------------

		//--------------114.80.208.143传输数据[start]----------------
		/*加快发送速度，暂时不发送
		$conn_id = ftp_connect('114.80.208.143');
		$login_result = ftp_login($conn_id, 'zhangjichao_sitestar', '383jkUElA76FEE29EB6');
		if ((!$conn_id) || (!$login_result)) 
		{
			$conn_id = ftp_connect('114.80.208.143');
			$login_result = ftp_login($conn_id, 'zhangjichao_sitestar', '383jkUElA76FEE29EB6');//两次试图链接
			if ((!$conn_id) || (!$login_result))
			{
				$this->write_log("114.80.208.143的ftp连接失败");
				return "114.80.208.143的ftp连接失败";
			}
		}
		$upload = ftp_put($conn_id, "./{$param2}_2_sample.sql", "./{$param2}_2_sample.sql", FTP_BINARY);
		if(!$upload)
		{
			$this->write_log("{$param2}_2_sample.sql传送到114.80.208.143失败");
			return "{$param2}_2_sample.sql传送到114.80.208.143失败";
		}
		$upload = ftp_put($conn_id, "./{$param2}_2_upload.zip", "./zjc/{$param2}_2_upload.zip", FTP_BINARY);
		if(!$upload)
		{
			$this->write_log("{$param2}_2_upload.zip传送到114.80.208.143失败");
			return "{$param2}_2_upload.zip传送到114.80.208.143失败";
		}
		ftp_close($conn_id);
		unset($conn_id);
		$this->write_log("114.80.208.143数据发送成功");
		*/
		//--------------114.80.208.143传输数据[end]----------------

		//--------------114.80.156.105传输数据[start]----------------
		$conn_id = ftp_connect('114.80.156.105');
		$login_result = ftp_login($conn_id, 'zhangjichao_sitestar', '383jkUElA76FEE29EB6');
		if ((!$conn_id) || (!$login_result)) 
		{
			$conn_id = ftp_connect('114.80.156.105');
			$login_result = ftp_login($conn_id, 'zhangjichao_sitestar', '383jkUElA76FEE29EB6');//两次试图链接
			if ((!$conn_id) || (!$login_result))
			{
				$this->write_log("114.80.156.105的ftp连接失败");
				return "114.80.156.105的ftp连接失败";
			}
		}
		$upload = ftp_put($conn_id, "./{$param2}_2_sample.sql", "./{$param2}_2_sample.sql", FTP_BINARY);
		if(!$upload)
		{
			$this->write_log("{$param2}_2_sample.sql传送到114.80.156.105失败");
			return "{$param2}_2_sample.sql传送到114.80.156.105失败";
		}
		$upload = ftp_put($conn_id, "./{$param2}_2_upload.zip", "./zjc/{$param2}_2_upload.zip", FTP_BINARY);
		if(!$upload)
		{
			$this->write_log("{$param2}_2_upload.zip传送到114.80.156.105失败");
			return "{$param2}_2_upload.zip传送到114.80.156.105失败";
		}
		ftp_close($conn_id);
		unset($conn_id);
		$this->write_log("114.80.156.105数据发送成功");
		//--------------114.80.156.105传输数据[end]----------------

		//--------------218.213.225.213传输数据[start]----------------
		/*
		$conn_id = ftp_connect('218.213.225.213');
		$login_result = ftp_login($conn_id, 'zhangjichao_sitestar', '383jkUElA76FEE29EB6111');
		if ((!$conn_id) || (!$login_result)) 
		{
			$conn_id = ftp_connect('218.213.225.213');
			$login_result = ftp_login($conn_id, 'zhangjichao_sitestar', '383jkUElA76FEE29EB6111');//两次试图链接
			if ((!$conn_id) || (!$login_result))
			{
				$this->write_log("218.213.225.213的ftp连接失败");
				return "218.213.225.213的ftp连接失败";
			}
		}
		$upload = ftp_put($conn_id, "./{$param2}_2_sample.sql", "./{$param2}_2_sample.sql", FTP_BINARY);
		if(!$upload)
		{
			$this->write_log("{$param2}_2_sample.sql传送到218.213.225.213失败");
			return "{$param2}_2_sample.sql传送到218.213.225.213失败";
		}
		$upload = ftp_put($conn_id, "./{$param2}_2_upload.zip", "./zjc/{$param2}_2_upload.zip", FTP_BINARY);
		if(!$upload)
		{
			$this->write_log("{$param2}_2_upload.zip传送到218.213.225.213失败");
			return "{$param2}_2_upload.zip传送到218.213.225.213失败";
		}
		ftp_close($conn_id);
		unset($conn_id);
		$this->write_log("218.213.225.213数据发送成功");
		//--------------218.213.225.213传输数据[end]----------------
		*/
		$this->write_log("数据传送到各台服务器成功");
		return 'ok';
		
	}
	//---------ftp传输模板数据[end]-------------
	
	//---------清理临时文件[start]-------------
	public function end()
	{
		$param2 = $this->param2;
		$param4 = $this->param4;
		$bool = false;
		$bool = $this->full_rmdir('./template');
		if(!$bool)
		{
			$this->write_log("删除template目录失败");
			return "删除template目录失败";
		}
		
		$bool = $this->full_rmdir("./{$param2}_2_upload");
		if(!$bool)
		{
			$this->write_log("删除{$param2}_2_upload目录失败");
			return "删除{$param2}_2_upload目录失败";
		}
		@unlink("./{$param2}_2_sample.sql");
		@unlink("./{$param2}.gif");
		@unlink("./$param4.jpg");
		@unlink("./{$param2}.zip");
		@unlink("./dsm/{$param2}.zip");
		@unlink("./zjc/{$param2}_2_upload.zip");
		$this->write_log("删除临时文件成功");
		$this->write_log("-------------{$param2}发布结束-------------");
		return 'ok';
	}
	
	public function full_rmdir($dir )
	{
		if(!is_writable($dir))
		{
			if(!@chmod($dir, 0777))
			{
				return false;
			}
		}
		 
		$d = @dir($dir);
		while (false !== ($entry = $d->read()))
		{
			if ($entry == '.' || $entry == '..')
			{
				continue;
			}
			$entry = $dir . '/' . $entry;
			if(is_dir($entry))
			{
				if (!$this->full_rmdir($entry))
				{
					return false;
				}
				continue;
			}
			if(!@unlink($entry))
			{
				$d->close();
				return false;
			}
		}
		 
		$d->close();
		 
		@rmdir($dir);
		 
		return true;
	}
	//---------清理临时文件[end]-------------
	
	//-------------记录日志[start]--------------------
	public function write_log($log_items)
	{
		$time = time();
		$time = date('Y-m-d H:i:s',$time);
		$time = '[' . $time . ']';
		
		if(empty($log_items))
		{
			die("{$time}:记录日志数据为空");
		}
		
		$log_items = $time.':'.$log_items."\r\n";
		
		if(!$handle = fopen('log.txt', 'a')) 
		{
			die("{$time}:不能打开log.txt");
		}
		if(fwrite($handle, $log_items) === FALSE)
		{
			die("{$time}:log.txt不能写");
		}
		fclose($handle);
	}
	//-------------记录日志[start]--------------------
}

class Zipper extends ZipArchive
{
	public function addDir($path)
	{
		//		print 'adding ' . $path . '<br>';
		$this->addEmptyDir($path);
		$nodes = glob($path . '/*');
		foreach ($nodes as $node)
		{
			if (is_dir($node))
			{
				$this->addDir($node);
			}
			else if (is_file($node))
			{
				$this->addFile($node);
			}
		}
	}
}

//$server = new SoapServer('PublishTemplate.wsdl');
//$server->setClass('PublishTemplate');
//$server->handle();
?>